const readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
const { writeToPageJson, makeTemplate } = require('./utils/index');
const pagesJson = './pages.json';

function askQuestion(question) {
    return new Promise((resolve, reject) => {
        rl.question(question, (input) => {
            resolve(input)
        })
    })
}
var _dirname = null;
askQuestion('输入想创建的页面模板文件夹？').then(dirname => {
    _dirname = dirname
})
    .then(() => {
        askQuestion('输入想创建的页面中文名称？').then(title => {
            let data = {
                name: _dirname,
                title,
                template: `pages/${_dirname}/${_dirname}.html`
            }
            makeTemplate(data)
            writeToPageJson(pagesJson, title, _dirname)
                .then(() => {

                    rl.close();
                })
        })
    })

// close事件监听
rl.on("close", function () {
    // 结束程序
    process.exit(0);
});
